home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / vbcc-wos-src / vlink / vlink.h < prev   
C/C++ Source or Header  |  1999-01-01  |  26KB  |  673 lines

  1. /* $VER: vlink vlink.h V0.6d (13.02.99)
  2.  *
  3.  * This file is part of vlink, a portable linker for multiple
  4.  * object formats.
  5.  * Copyright (c) 1997-99  Frank Wille
  6.  *
  7.  * vlink is freeware and part of the portable and retargetable ANSI C
  8.  * compiler vbcc, copyright (c) 1995-99 by Volker Barthelmann.
  9.  * vlink may be freely redistributed as long as no modifications are
  10.  * made and nothing is charged for it. Non-commercial usage is allowed
  11.  * without any restrictions.
  12.  * EVERY PRODUCT OR PROGRAM DERIVED DIRECTLY FROM MY SOURCE MAY NOT BE
  13.  * SOLD COMMERCIALLY WITHOUT PERMISSION FROM THE AUTHOR.
  14.  *
  15.  *
  16.  * v0.6b (16.01.99) phx
  17.  *       big_endian has to be "signed char" to compile under Irix 5.3.
  18.  * v0.6a (19.12.98) phx
  19.  *       Endianess of linking process will be determined by the type
  20.  *       of the first object.
  21.  *       Support for little endian object file formats.
  22.  *       New macros read16, write16, read32, write32 (replacing the old
  23.  *       macros with the same name) for reading/writing data in the
  24.  *       current endian format.
  25.  * v0.6  (24.10.98) phx
  26.  *       baserel_off disappeared. Each target should know about its
  27.  *       own small data section offset for the base register. The new
  28.  *       field baseoff in FFFuncs was created for this purpose.
  29.  *       New target elf32powerup, which supports the PPC coprocessor
  30.  *       boards from Phase5.
  31.  * v0.5e (05.10.98) phx
  32.  *       Artificial sections and objects, containing longwords sorted
  33.  *       by priority, may be generated using new_priptr().
  34.  *       Reduced hash table size for objects to 1/8 (32 entries).
  35.  * v0.5d (22.08.98) phx
  36.  *       Faster memory allocation can be activated by #define FASTALLOC.
  37.  *       Directories are only scanned if needed (AmigaOS filesystem is
  38.  *       too slow).
  39.  * v0.5c (08.07.98) phx
  40.  *       Automagic generation of @__xxx symbols for amigaehf.
  41.  * v0.5b (05.07.98) phx
  42.  *       Linker symbols for elf32ppcbe.
  43.  *       SYMX_SPECIAL in Symbol->extra flags a linker symbol as
  44.  *       being target-specific
  45.  * v0.5  (27.06.98) phx
  46.  *       Target-specific linker symbol support.
  47.  * v0.4  (05.06.98) phx
  48.  *       New global vars for options: -sc, -sd, -multibase.
  49.  *       New target-specific function targetlink(), which decides whether
  50.  *       two sections must or must not be linked together for a target.
  51.  *       find/create_lnksect() from linker.c are no longer global.
  52.  *       linker_relrefs() finds all relative references between sections.
  53.  *       The sections contain a RelRef-list afterwards, which can be
  54.  *       used to link sections with relative references automatically
  55.  *       together.
  56.  * v0.3b (25.04.98) phx
  57.  *       t_elf.c was split into t_elf32.c and t_elf64.c
  58.  *       New header files: elf64.h and rel_elfalpha.h
  59.  *       Some experimental code for target elf64alpha in t_elf64.c
  60.  * v0.3a (18.04.98) phx
  61.  *       Updated help text.
  62.  * v0.3  (17.04.98) phx
  63.  *       ELF PowerPC 32Bit Big Endian support. Input: objects and
  64.  *       library archives. Output: relocatabable objects.
  65.  *       Full support for little endian file formats by defining new
  66.  *       macros: LECH,LECW,LECVH,LECVW,read16le,read32le,write16le,
  67.  *       write32le (although currently no LE formats are supported).
  68.  *       Replaced l2bh(),l2bw(),read16(),read32(),write16(),write32()
  69.  *       by swap16(),swap32(),read16sw(),read32sw(),write16sw(),write32sw().
  70.  *       fwrite32() is now called fwrite32be().
  71.  *       Section.id may contain a unique identification value.
  72.  *       Included objname in struct LinkFile (useful for ELF archives).
  73.  *       New option -F for reading a list of input files.
  74.  *       Support for ar library archives.
  75.  * v0.2  (07.03.98) phx
  76.  *       Linking of EHF and ADOS seems quite stable. Library units
  77.  *       are linked immediately and are no longer always the last
  78.  *       units in an output file.
  79.  *       insertnode().
  80.  * v0.1  (27.02.98) phx
  81.  *       First version that seems to link AmigaOS ADOS and EHF
  82.  *       objects and libraries. Many common features, like linking
  83.  *       sections together which have relative references, are
  84.  *       still missing. Also, PowerPC-ELF32 support is about to come.
  85.  * v0.0  (04.08.97) phx
  86.  *       File created. Project started on a beautiful summer-day
  87.  *       at the North Sea beach of Cuxhaven. :)
  88.  */
  89.  
  90. #include <stdlib.h>
  91. #include <stdio.h>
  92. #include <string.h>
  93. #include <stdarg.h>
  94. #include <ctype.h>
  95.  
  96. #ifdef HAVE_CONFIG
  97. #include "config.h"
  98. #endif
  99.  
  100. /* program's name */
  101. #define PNAME "vlink"
  102.  
  103. /* version/revision */
  104. #define VERSION 0
  105. #define REVISION 6
  106. #define PLEVEL 4
  107.  
  108.  
  109. /* integer types */
  110. #if defined (TYPES32BIT)
  111. typedef signed char int8;
  112. typedef unsigned char uint8;
  113. typedef signed short int int16;
  114. typedef unsigned short int uint16;
  115. typedef signed long int int32;
  116. typedef unsigned long int uint32;
  117. typedef signed char bool;
  118. #elif defined (TYPES64BIT)
  119. typedef signed char int8;
  120. typedef unsigned char uint8;
  121. typedef signed short int16;
  122. typedef unsigned short uint16;
  123. typedef signed int int32;
  124. typedef unsigned int uint32;
  125. typedef int bool;
  126. #else
  127. #error Unsupported architecture! Define either TYPES32BIT or TYPES64BIT.
  128. #endif
  129.  
  130.  
  131. /* endian conversion */
  132. #if defined (BIGENDIAN)
  133. #define ECH(x) x
  134. #define ECW(x) x
  135. #define ECVH(x) x
  136. #define ECVW(x) x
  137. #define read16be(x) (*(uint16 *)(x))
  138. #define read32be(x) (*(uint32 *)(x))
  139. #define write16be(x,y) (*(uint16 *)(x)=(y))
  140. #define write32be(x,y) (*(uint32 *)(x)=(y))
  141. #define LECH(x) (((x)&0xff)<<8|((x)&0xff00)>>8)
  142. #define LECW(x) (((x)&0xff)<<24|((x)&0xff00)<<8|((x)&0xff0000)>>8|((x)&0xff000000)>>24)
  143. #define LECVH(x) swap16(x)
  144. #define LECVW(x) swap32(x)
  145. #define read16le(x) read16sw(x)
  146. #define read32le(x) read32sw(x)
  147. #define write16le(x,y) write16sw(x,y)
  148. #define write32le(x,y) write32sw(x,y)
  149.  
  150. #elif defined (LITTLEENDIAN)
  151. #define ECH(x) (((x)&0xff)<<8|((x)&0xff00)>>8)
  152. #define ECW(x) (((x)&0xff)<<24|((x)&0xff00)<<8|((x)&0xff0000)>>8|((x)&0xff000000)>>24)
  153. #define ECVH(x) swap16(x)
  154. #define ECVW(x) swap32(x)
  155. #define read16be(x) read16sw(x)
  156. #define read32be(x) read32sw(x)
  157. #define write16be(x,y) write16sw(x,y)
  158. #define write32be(x,y) write32sw(x,y)
  159. #define LECH(x) x
  160. #define LECW(x) x
  161. #define LECVH(x) x
  162. #define LECVW(x) x
  163. #define read16le(x) (*(uint16 *)(x))
  164. #define read32le(x) (*(uint32 *)(x))
  165. #define write16le(x,y) (*(uint16 *)(x)=(y))
  166. #define write32le(x,y) (*(uint32 *)(x)=(y))
  167. #else
  168. #error You have to define either BIGENDIAN or LITTLEENDIAN.
  169. #endif
  170.  
  171. /* read/write data in current endianess */
  172. #define read16(e,x) ((e)?(read16be(x)):(read16le(x)))
  173. #define read32(e,x) ((e)?(read32be(x)):(read32le(x)))
  174. #define write16(e,x,y) if(e) write16be(x,y); else write16le(x,y)
  175. #define write32(e,x,y) if(e) write32be(x,y); else write32le(x,y)
  176.  
  177. /* program constants */
  178.  
  179. #ifndef TRUE
  180. #define TRUE 1
  181. #endif
  182. #ifndef FALSE
  183. #define FALSE 0
  184. #endif
  185. #ifndef NULL
  186. #define NULL 0
  187. #endif
  188.  
  189. #define FNAMEBUFSIZE 1024       /* buffer size for file names */
  190. #define MAX_FWALIGN 8192        /* max. aligment, when writing target file */
  191.  
  192.  
  193. /* structures */
  194.  
  195. struct node {
  196.   struct node *next;
  197.   struct node *pred;
  198. };
  199.  
  200. struct list {
  201.   struct node *first;
  202.   struct node *dummy;
  203.   struct node *last;
  204. };
  205.  
  206.  
  207. struct LibPath {                /* libpaths list. */
  208.   struct node n;                /* Here we search for library archives */
  209.   char *path;                   /* and shared objects. */
  210. };
  211.  
  212.  
  213. struct InputFile {              /* inputlist nodes */
  214.   struct node n;                /* contains names & flags of all inp. files */
  215.   char *name;
  216.   bool lib;                     /* search library */
  217.   bool dynamic;                 /* try to link dynamic first */
  218.   int so_ver;                   /* minimum version of shared object */
  219. };
  220.  
  221.  
  222. struct LinkFile {
  223.   struct node n;
  224.   char *pathname;               /* full path: /usr/lib/libm.a */
  225.   char *filename;               /* file name: libm.a */
  226.   char *objname;                /* current obj. name: sin.o (archives only)*/
  227.   uint8 *data;                  /* pointer to file data */
  228.   unsigned long length;         /* length of file */
  229.   uint8 format;                 /* file format - index into targets table */
  230.   uint8 type;                   /* ID_OBJECT/SHAREDOBJ/LIBARCH */
  231. };
  232.  
  233.  
  234. struct ObjectUnit {
  235.   struct node n;
  236.   struct LinkFile *lnkfile;     /* LinkFile, where the obj. belongs to */
  237.   char *objname;                /* name of object, if available, e.g. sin.o */
  238.   struct list sections;         /* list of all sections in this object */
  239.   struct Symbol **objsyms;      /* all symbols from this object unit */
  240.   uint16 flags;
  241.   struct list pripointers;      /* PriPointers of this unit */
  242. };
  243.  
  244. #define OUF_LINKED 0x0001       /* object unit is marked as linked */
  245. #define OBJSYMHTABSIZE 0x20     /* number of entries in symbol hash table */
  246.  
  247. struct RelRef {
  248.   struct RelRef *next;
  249.   struct Section *refsec;       /* relative referenced sections */
  250. };
  251.  
  252. struct Section {
  253.   struct node n;
  254.   struct ObjectUnit *obj;       /* link to ObjectUnit */
  255.   struct LinkedSection *lnksec; /* ptr to joined sections */
  256.   char *name;                   /* section's name, e.g. .text, .data, ... */
  257.   uint32 id;                    /* unique section id - target dependant */
  258.   uint8 type;                   /* type: code, data, bss */
  259.   uint8 flags;
  260.   uint8 protection;             /* readable, writable, executable, ... */
  261.   uint8 alignment;              /* number of bits, which have to be zero */
  262.   unsigned long va;             /* the section's virtual address */
  263.   unsigned long offset;         /* offset relative to 1st sec. of same type */
  264.   uint8 *data;                  /* the section's contents */
  265.   unsigned long size;           /* the section's size in bytes (+alignment) */
  266.   struct list relocs;           /* the section's 32-bit relocations */
  267.   struct list xrefs;            /* external references to unknown symbols */
  268.   struct RelRef *relrefs;       /* all sections which are referenced rel. */
  269. };
  270.  
  271. /* section types */
  272. #define ST_UNDEFINED 0
  273. #define ST_CODE 1               /* section contains code */
  274. #define ST_DATA 2               /* section contains initialized data */
  275. #define ST_UDATA 3              /* section contains uninitialized data */
  276. #define ST_LAST 3               /* last section type */
  277.  
  278. /* section flags */
  279. #define SF_DISCARD 0x1          /* can be discarded */
  280. #define SF_UNINITIALIZED 0x2    /* section has uninitialized contents */
  281. #define SF_SMALLDATA 0x4        /* section is referenced base-relative */
  282. #define SF_PORTABLE_MASK 0x0f   /* mask for target-independant flags */
  283. /* target specific section flags */
  284. #define SF_EHFPPC 0x20          /* target ehf: section contains PPC code */
  285. #define SF_CHIP 0x40            /* target amigaos: Chip-RAM section */
  286. #define SF_FAST 0x80            /* target amigaos: Fast-RAM section */
  287.  
  288. /* protection */
  289. #define SP_READ 1
  290. #define SP_WRITE 2
  291. #define SP_EXEC 4
  292. #define SP_SHARE 8
  293.  
  294.  
  295. struct Reloc {
  296.   struct node n;
  297.   union {
  298.     uint32 id;                  /* section index */
  299.     struct Section *ptr;        /* base addr of this sect. has to be added */
  300.     struct LinkedSection *lnk;  /* base addr of joined sections */
  301.   } relocsect;
  302.   unsigned long offset;         /* section-offset of relocation */
  303.   int32 addend;                 /* add this to relocation value */
  304.   uint8 type;
  305. };
  306.  
  307. /* relocation types */
  308. #define R_NONE 0
  309. #define R_ADDR32 1              /* 32-bit relocation */
  310. #define R_ADDR26 2              /* PPC 26-bit relocation */
  311. #define R_ADDR16 3              /* 16-bit relocation */
  312. #define R_ADDR16_LO 4           /* relocation of the lower 16-bit word */
  313. #define R_ADDR16_HI 5           /* relocation of the higher 16-bit word */
  314. #define R_ADDR16_HA 6           /* as HI, but add 1 if lower word is neg. */
  315. #define R_ADDR14 7              /* PPC/BC-instruction, 16-bit absolute */
  316. #define R_ADDR14_BRTAKEN 8
  317. #define R_ADDR14_BRNTAKEN 9
  318. #define R_ADDR8 10              /* 8-bit relocation */
  319.  
  320. #define R_REL32 32              /* relative 32-bit */
  321. #define R_REL26 33              /* relative PPC 26-bit */
  322. #define R_REL16 34              /* relative 16-bit */
  323. #define R_REL14 35              /* PPC/BC-instruction, 16-bit relative */
  324. #define R_REL14_BRTAKEN 36
  325. #define R_REL14_BRNTAKEN 37
  326. #define R_REL8 38               /* relative 8-bit */
  327.  
  328. #define R_BASEREL32 64          /* base register relative 32-bit */
  329. #define R_BASEREL26 65          /* base register relative 26-bit (PPC) */
  330. #define R_BASEREL16 66          /* base register relative 16-bit */
  331. #define R_BASEREL8 67           /* base register relative 8-bit */
  332.  
  333. #define R_MASK 0x60
  334. #define R_ADDR 0x00
  335. #define R_REL 0x20
  336. #define R_BASEREL 0x40
  337.  
  338. struct Symbol {
  339.   struct node n;
  340.   struct Symbol *glob_chain;    /* next symbol in global hash chain */
  341.   struct Symbol *obj_chain;     /* next symbol in object hash chain */
  342.   char *name;                   /* symbol's name */
  343.   uint32 value;                 /* abs. value, reloc. offset or alignment */
  344.   struct Section *relsect;      /* symbol def. relative to this section */
  345.   /* SYM_ABS are rel. to 1st section, SYM_COMMON rel. to a BSS section */
  346.   uint8 type;                   /* absolute, relocatable or extern */
  347.   uint8 flags;
  348.   uint8 info;                   /* section, function or object */
  349.   uint8 bind;                   /* local, global or weak binding */
  350.   uint32 size;                  /* symbol's size in bytes */
  351.   uint32 extra;                 /* extra data, used by some targets */
  352. };
  353.  
  354. /* symbol type */
  355. #define SYM_UNDEF 0
  356. #define SYM_ABS 1               /* absolute value */
  357. #define SYM_RELOC 2             /* relocation offset, relative to section */
  358. #define SYM_COMMON 3            /* alignment constraints in value */
  359.  
  360. /* symbol flags */
  361. #define SYMF_LNKSYM 1           /* a linker-generated symbol */
  362.  
  363. /* object type */
  364. #define SYMI_NOTYPE 0
  365. #define SYMI_OBJECT 1
  366. #define SYMI_FUNC 2
  367. #define SYMI_SECTION 3
  368. #define SYMI_FILE 4
  369.  
  370. /* symbol bind */
  371. #define SYMB_NONE 0
  372. #define SYMB_LOCAL 1
  373. #define SYMB_GLOBAL 2
  374. #define SYMB_WEAK 3
  375.  
  376. /* extra */
  377. #define SYMX_SPECIAL 0x80000000 /* Bit 31 = target-specific lnk. symbol */
  378.  
  379. struct XReference {
  380.   struct node n;
  381.   struct Symbol *symbol;        /* symbol-pointer, if x-ref. was resolved */
  382.   char *name;
  383.   unsigned long offset;         /* section offset of reference */
  384.   int32 addend;
  385.   uint8 type;                   /* relocation type, see struct Reloc */
  386.   uint8 size;                   /* size of reference in bytes (3 = 26bit) */
  387. };
  388.  
  389.  
  390. struct SymNames {
  391.   struct SymNames *next;        /* next symbol name in hash chain */
  392.   char *name;                   /* symbol's name */
  393. };
  394.  
  395.  
  396. struct SecBase {                /* definition of section base address */
  397.   struct SecBase *next;
  398.   char *name;
  399.   unsigned long base;
  400. };
  401.  
  402.  
  403. struct LinkedSection {          /* linked sections of same type and name */
  404.   struct node n;
  405.   int index;                    /* section index 0..gv->nsecs */
  406.   char *name;                   /* section's name, e.g. .text, .data, ... */
  407.   uint8 type;                   /* type: code, data, bss */
  408.   uint8 flags;
  409.   uint8 protection;             /* readable, writable, executable, ... */
  410.   uint8 alignment;              /* number of bits, which have to be zero */
  411.   unsigned long base;           /* the section's virtual address */
  412.   unsigned long size;           /* the section's size in bytes */
  413.   unsigned long filesize;       /* size in file, rest ist filled with '0' */
  414.   struct list sections;         /* s. which have been linked together */
  415.   struct RelRef *relrefs;       /* all sections which are referenced rel. */
  416.   uint8 *data;                  /* the section's contents */
  417.   struct list relocs;           /* the section's 32-bit relocations */
  418.   struct list xrefs;            /* external references to unknown symbols */
  419.   struct list symbols;          /* the section's symbol definitions */
  420. };
  421.  
  422.  
  423. struct FFFuncs {                /* file format specific functions and data */
  424.   const char *tname;            /* name of file format */
  425.   int (*identify)();            /* format identification */
  426.   void (*readconv)();           /* read file and convert into internal fmt. */
  427.   unsigned long (*secbase)();   /* default base address of a section */
  428.   uint8 (*cmpsecflags)();       /* compare target-specific section flags */
  429.   struct Section *(*bssdefault)(); /* create a default bss section */
  430.   int (*targetlink)();          /* chk. if target requires linking of sect.*/
  431.   struct Symbol *(*lnksymbol)();/* resolve linker-symbol reference */
  432.   void (*setlnksym)();          /* init sym structure during resolve_xref() */
  433.   void (*writeobject)();        /* write object file */
  434.   void (*writeshared)();        /* write shared object file */
  435.   void (*writeexec)();          /* write executable file */
  436.   int32 baseoff;                /* sec. offset in bytes for base registers */
  437.   struct Symbol **lnksyms;      /* linker symbols, supported by this target */
  438.   signed char big_endian;       /* 1=bigEndian, 0=littleEndian */
  439. };
  440.  
  441. /* Return codes from identify() */
  442. #define ID_UNKNOWN 0            /* unknown file format */
  443. #define ID_OBJECT 1             /* object file in current format */
  444. #define ID_EXECUTABLE 2         /* executable file in current format */
  445. #define ID_ARTIFICIAL 3         /* an art. object, created by the linker */
  446. /* ^ objects and executables must have a smaller id-value! */
  447. #define ID_LIBBASE 4            /* all ids >= 4 are libraries (s.o. or .a) */
  448. #define ID_SHAREDBASE 4
  449. #define ID_SHAREDOBJ 4          /* shared object file in current format */
  450. #define ID_ARCHBASE 8
  451. #define ID_LIBARCH 8            /* linker library archive in curr. format */
  452. /* number of entries in linker symbol hash table */
  453. #define LNKSYMHTABSIZE 0x10
  454.  
  455.  
  456. /* List of artificially generated pointers or long words, which are */
  457. /* sorted by ObjectUnit-name, section-name and priority. */
  458. struct PriPointer {
  459.   struct node n;
  460.   char *objname;
  461.   char *secname;
  462.   int priority;
  463.   char *xrefname;
  464.   uint32 addend;
  465. };
  466.  
  467.  
  468.  
  469. /* Global defines */
  470. #define DEF_MAXERRORS 999999    /* don't want this feature now... */
  471. #define STRIP_NONE 0
  472. #define STRIP_DEBUG 1           /* strip debugger symbols only */
  473. #define STRIP_ALL 2             /* strip all symbols */
  474. #define DISLOC_NONE 0
  475. #define DISLOC_TMP 1            /* discard temporary local symbols */
  476. #define DISLOC_ALL 2            /* discard all local symbols */
  477.  
  478.  
  479. struct GlobalVars {
  480.   /* options */
  481.   struct list libpaths;         /* paths where to search for libraries */
  482.   struct list inputlist;        /* list of input files */
  483.   char *dest_name;              /* output (executable) file name */
  484.   uint8 dest_format;            /* output file format */
  485.   bool dest_object;             /* output file is a relocatable object */
  486.   bool dest_sharedobj;          /* output as shared object */
  487.   bool alloc_common;            /* force allocation of common symbols */
  488.   bool whole_archive;           /* always link with whole archives */
  489.   uint8 strip_symbols;          /* strip symbols */
  490.   uint8 discard_local;          /* discard local symbols */
  491.   bool short_rel;               /* use short form for relocations */
  492.   bool small_code;              /* combine all code sections */
  493.   bool small_data;              /* combine all data sections */
  494.   bool multibase;               /* don't merge all base-rel. accessed sect.*/
  495.   FILE *map_file;               /* map file */
  496.   FILE *trace_file;             /* linker trace output */
  497.   struct SymNames **trace_syms; /* trace-symbol hash table */
  498.   struct SecBase *secbases;     /* section base addr., as defined by -T */
  499.  
  500.   /* errors */
  501.   bool dontwarn;                /* suppress warnings */
  502.   bool errflag;                 /* if true, don't create output file */
  503.   int maxerrors;                /* # of errors to display, before aborting */
  504.   int errcnt;                   /* number of errors displayed */
  505.   int returncode;               /* return code for exit() */
  506.  
  507.   /* linking process */
  508.   struct list linkfiles;        /* list of all link files (obj., libs,...)*/
  509.   struct list selobjects;       /* list of included object units */
  510.   struct list libobjects;       /* list of non-included library-objects */
  511.   struct list sharedobjects;    /* list of shared objects */
  512.   struct Symbol **symbols;      /* global symbol hash table */
  513.   struct list pripointers;      /* list of PriPointer nodes */
  514.   struct list lnksec;           /* list of linked sections */
  515.   int nsecs;                    /* total number of sections in lnksec */
  516.   signed char big_endian;       /* linking in big endian mode (1), */
  517.                                 /*  little endian (0), undefined (-1) */
  518. };
  519.  
  520. #define SYMHTABSIZE 0x10000     /* number of entries in symbol hash table */
  521. #define TRSYMHTABSIZE 0x40
  522.  
  523.  
  524. /* global functions */
  525. #include "ar.h"
  526.  
  527. /* main.c */
  528. #ifndef MAIN_C
  529. extern struct GlobalVars gvars;
  530. extern void cleanup(struct GlobalVars *);
  531. #endif
  532.  
  533. /* version.c */
  534. #ifndef VERSION_C
  535. extern void show_version(void);
  536. extern void show_usage(void);
  537. #endif
  538.  
  539. /* support.c */
  540. #ifndef SUPPORT_C
  541. #ifdef FASTALLOC
  542. extern void init_mem(void);
  543. #endif
  544. extern void *alloc(size_t);
  545. extern void *alloczero(size_t);
  546. extern char *allocstring(char *);
  547. extern void *alloc_hashtable(size_t);
  548. extern void initlist(struct list *);
  549. extern void insertbefore(struct node *,struct node *);
  550. extern void insertbehind(struct node *,struct node *);
  551. extern void addhead(struct list *,struct node *);
  552. extern void addtail(struct list *,struct node *);
  553. extern struct node *remhead(struct list *);
  554. extern struct node *remnode(struct node *);
  555. extern char *mapfile(char *);
  556. extern char *base_name(char *);
  557. extern char *check_name(char *);
  558. extern int checkrange(uint32,int,bool);
  559. extern uint16 swap16(uint16);
  560. extern uint32 swap32(uint32);
  561. extern uint16 read16sw(uint8 *);
  562. extern uint32 read32sw(uint8 *);
  563. extern void write16sw(uint8 *,uint16);
  564. extern void write32sw(uint8 *,uint32);
  565. extern void fwritex(FILE *,void *,size_t);
  566. extern void fwrite32be(FILE *,uint32);
  567. extern void fwrite_align(FILE *,uint32,uint32);
  568. extern unsigned long elf_hash(unsigned char *);
  569. extern unsigned long align(unsigned long,unsigned long);
  570. extern int shiftval(uint32);
  571. #endif
  572. #define listempty(x) ((x)->first->next==NULL)
  573.  
  574. /* errors.c */
  575. #ifndef ERRORS_C
  576. extern void error(int,...);
  577. extern void ierror(char *,...);
  578. #endif
  579.  
  580. /* linker.c */
  581. #ifndef LINKER_C
  582. extern void linker_init(struct GlobalVars *);
  583. extern void linker_load(struct GlobalVars *);
  584. extern void linker_resolve(struct GlobalVars *);
  585. extern void linker_relrefs(struct GlobalVars *);
  586. extern void linker_join(struct GlobalVars *);
  587. extern void linker_copy(struct GlobalVars *);
  588. extern void linker_relocate(struct GlobalVars *);
  589. extern void linker_write(struct GlobalVars *);
  590. extern void linker_cleanup(struct GlobalVars *);
  591. extern char *getobjname(struct ObjectUnit *);
  592. extern void print_function_name(struct Section *,unsigned long);
  593. extern bool trace_sym_access(struct GlobalVars *,char *);
  594. #endif
  595.  
  596. /* targets.c */
  597. #ifndef TARGETS_C
  598. extern struct FFFuncs *fff[];
  599. extern const char *sym_type[];
  600. extern const char *sym_info[];
  601. extern const char *sym_bind[];
  602. extern unsigned long findsecbase(struct GlobalVars *,char *);
  603. extern struct Symbol *findsymbol(struct GlobalVars *,char *name);
  604. extern struct Symbol *addsymbol(struct GlobalVars *,struct Section *,
  605.                                 char *,uint32,uint8,uint8,uint8,uint8,uint32);
  606. extern void addlocsymbol(struct GlobalVars *,struct Section *,char *,uint32,
  607.                          uint8,uint8,uint8,uint32);
  608. extern void addglobsym(struct GlobalVars *,struct Symbol *);
  609. extern struct Symbol *addlnksymbol(struct FFFuncs *,struct Section *,char *,
  610.                                    uint32,uint8,uint8,uint8,uint8,uint32);
  611. extern struct Symbol *findlnksymbol(struct FFFuncs *,char *);
  612. extern void addreloc(struct Section *,struct Section *,uint32,uint32,
  613.                      uint8,int32);
  614. extern void addxref(struct GlobalVars *,struct Section *,char *,uint32,
  615.                     uint8,uint8,int32);
  616. extern int32 readsection(struct GlobalVars *,uint8 *,uint8);
  617. extern void writesection(struct GlobalVars *,uint8 *,uint8,uint32);
  618. extern uint8 relocsize(uint8);
  619. extern struct Section *create_section(struct ObjectUnit *,char *,
  620.                                       uint8 *,unsigned long);
  621. extern struct Section *find_sect_type(struct ObjectUnit *,uint8,uint8);
  622. extern struct Section *find_sect_id(struct ObjectUnit *,uint32);
  623. extern struct LinkedSection *find_lnksec(struct GlobalVars *,char *,uint8,
  624.                                          uint8,uint8);
  625. extern struct LinkedSection *smalldata_section(struct GlobalVars *);
  626. extern void add_objunit(struct GlobalVars *,struct ObjectUnit *,bool);
  627. extern struct ObjectUnit *create_objunit(struct LinkFile *,char *);
  628. extern struct ObjectUnit *art_objunit(char *,uint8 *,unsigned long,uint8);
  629. extern void new_priptr(struct ObjectUnit *,char *,char *,int,char *,uint32);
  630. extern void add_priptrs(struct GlobalVars *,struct ObjectUnit *);
  631. extern void make_priptr_objects(struct GlobalVars *);
  632. extern bool ar_init(struct ar_info *,char *,unsigned long,char *);
  633. extern bool ar_extract(struct ar_info *);
  634. #endif
  635.  
  636. /* t_amigaos.c */
  637. #if defined(AMIGAOS) || defined(EHF)
  638. #ifndef T_AMIGAOS_C
  639. extern struct FFFuncs fff_amigaos;
  640. extern struct FFFuncs fff_ehf;
  641. #endif
  642. #endif
  643.  
  644. /* dir.c */
  645. #ifndef DIR_C
  646. extern char *open_dir(char *);
  647. extern char *read_dir(char *);
  648. extern void close_dir(char *);
  649. extern bool chk_file(char *);
  650. #endif
  651.  
  652. /* relocnames.c */
  653. extern char *reloc_name[];
  654.  
  655. /* t_elf32.c */
  656. #if defined(ELF32_PPC_BE)
  657. #ifndef T_ELF32_C
  658. extern struct FFFuncs fff_elf32ppcbe;
  659. #endif
  660. #endif
  661. #if defined(ELF32_POWERUP)
  662. #ifndef T_ELF32_C
  663. extern struct FFFuncs fff_elf32powerup;
  664. #endif
  665. #endif
  666.  
  667. /* t_elf64.c */
  668. #if defined(ELF64_ALPHA)
  669. #ifndef T_ELF64_C
  670. extern struct FFFuncs fff_elf64alpha;
  671. #endif
  672. #endif
  673.